package com.project.controller;
import com.github.pagehelper.PageInfo;
import com.project.bean.ProductBean;
import com.project.service.IProductService;
import com.project.until.UploadUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.time.LocalDate;

@RestController
@RequestMapping("product")
public class ProductController {
    @Autowired
    private IProductService service;

    @RequestMapping("findByItem")
    public PageInfo<ProductBean>findByItem(int pageNo,String name,  LocalDate startDate,LocalDate endDate,String status){
        return service.findByItem(pageNo,name, startDate,endDate,status);
    }
    @RequestMapping("add")
    public String add(ProductBean product, @RequestParam("face")MultipartFile mf){
        System.out.println("ppppppppppppppppppppppppppppppp");
        String fileName= UploadUtil.upload(mf,"static/html/img");
        System.out.println("323333333333333333333333333");
        product.setImgPath(fileName);
        service.add(product);
        return "ok";
    }

    @RequestMapping("updateStatus")
    public String updateStatus(int id,String productStatus){
        service.updateStatus(id, productStatus);
        return "ok";
    }

    @RequestMapping("updatePrice")
    public String updatePrice(int productId,int price){
        service.updatePrice(productId,price);
        return "ok";
    }

    @RequestMapping("findById")
    public ProductBean findById(int id){
        return service.findById(id);
    }
}
